package cn.honglian.basic.controller;


import cn.honglian.basic.dto.FountPhoneLoginDto;
import cn.honglian.basic.service.VerifyCodeService;
import cn.honglian.basic.util.AjaxResult;
import cn.honglian.user.dto.VerificationCodeDto;
import cn.honglian.user.dto.VerifyMailboxCodeDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private VerifyCodeService service;

    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult graph(@PathVariable("imageCodeKey") String imageCodeKey) throws IOException {
      String base64 =  service.graph(imageCodeKey);

        return AjaxResult.me().success(base64);
    }

    /*
        用户注册获取验证码
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody VerificationCodeDto verificationCodeDto){
        service.smsCode(verificationCodeDto);

        return AjaxResult.me().success();
    }
    @PostMapping("/emailCode")
    public AjaxResult eamilCode(@RequestBody VerifyMailboxCodeDto dto){
        service.emailCode(dto);

        return AjaxResult.me().success();
    }

    /*
        用户登录获取验证码
     */
    @PostMapping("/smsCode/phone")
    public AjaxResult smsCodePhone(@RequestBody FountPhoneLoginDto dto){
        service.smsCodePhone(dto);

        AjaxResult success = AjaxResult.me().success();
        return success;
    }



}
